using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Bean;
using Shpm.System.Db;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Commons.Db.Beans.Master;

/// <summary>
/// Summary description for NotifyMessageDao
/// </summary>
namespace Shpm.App.Input.Dao
{
    public class NotifyMessageDao : ShpmBaseDao
    {
        public const string FIND_BY_NOTIFY_MESSAGE = "NotifyMessage.FindByNotifyMessage";
        public const string GET_NOTIFY_MESSAGE = "NotifyMessage.GetNotifyMessage";
        public const string INS_MESSAGE = "NotifyMessage.InsMessage";
        public const string INS_NOTIFY_MESSAGE = "NotifyMessage.InsNotifyMessage";
        public const string FIND_BY_GROUP = "NotifyMessage.FindByGroup";
        public const string GET_DEPARTMENT_LIST = "NotifyMessage.GetDepartmentList";
        public const string FIND_DEPART_BY_MESSAGE = "NotifyMessage.FindDepartByMessage";
        public const string LIST_NOTIFY_MESSAGE = "NotifyMessage.ListNotifyMessage";

        public NotifyMessageDao()
        {
        }

        public IList FindByNotifyMessage(MessageBean paramBean)
        {
            return base.QueryForList(FIND_BY_NOTIFY_MESSAGE, paramBean);
        }

        public IList ListNotifyMessage(MessageBean paramBean)
        {
            return base.QueryForList(LIST_NOTIFY_MESSAGE, paramBean);
        }

        public MessageBean Load(MessageBean paramBean)
        {
            return (MessageBean)base.QueryForObject(GET_NOTIFY_MESSAGE, paramBean);
        }

        public MessageBean Insert(MessageBean paramBean)
        {
            int messageId = (int)base.Insert(INS_MESSAGE, paramBean);
            paramBean.MessageId = messageId;

            return paramBean;
        }

        public InpNotifyMessageBean Insert(InpNotifyMessageBean paramBean)
        {
            return (InpNotifyMessageBean)base.Insert(INS_NOTIFY_MESSAGE, paramBean);
        }

        /*
        public IList FindByGroup(MstGroupBean paramBean)
        {
            return base.QueryForList(FIND_BY_GROUP, paramBean);
        }
        */

        public IList GetDepartmentList()
        {
            return base.QueryForList(GET_DEPARTMENT_LIST, new MstGroupBean());
        }

        public IList FindDepartByMessage(MessageBean paramBean)
        {
            return base.QueryForList(FIND_DEPART_BY_MESSAGE, paramBean);
        }

        public void InsertMessage(MessageBean messageBean, IList groupList)
        {
            try
            {
                base.BeginTransaction();

                messageBean = this.Insert(messageBean);
                IEnumerator enm = groupList.GetEnumerator();
                while (enm.MoveNext())
                {
                    MstDepartmentBean departBean = (MstDepartmentBean)enm.Current;
                    InpNotifyMessageBean notifyMessageBean = new InpNotifyMessageBean();
                    notifyMessageBean.MessageId = messageBean.MessageId;
                    notifyMessageBean.DepartId = departBean.DepartId;
                    this.Insert(notifyMessageBean);
                }

                base.CommitTransaction();
            }
            catch(Exception e)
            {
                base.RollBackTransaction();
                throw e;
            }
        }
    }
}